import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution523 {
    public boolean checkSubarraySum(int[] nums, int k) {
        int cur=0;
        Map<Integer, List<Integer>> map=new HashMap<>();
        List<Integer> list=new ArrayList<>();
        list.add(0);
        map.put(0,list);
        for (int i=0;i<nums.length;i++){
            cur=(cur+nums[i]%k)%k;
            List<Integer> l=map.getOrDefault(cur,new ArrayList<>());
            if (l.size()>=1 && i-l.get(0)>=1){
                return true;
            }
            l.add(i+1);
            map.put(cur,l);
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution523().checkSubarraySum(new int[]{23,2,6,4,7},13));
    }
}
